package com.swyc.osschat.Test.designMode.iterator.impl;

import com.swyc.osschat.Test.designMode.iterator.base.Iterator;

import java.util.List;

/**
 * @description 具体迭代器
 * @Author: z156940l@outlook.com
 * @className ObjectIterator
 * @Date: 2022/6/28 8:42
 */
public class ObjectIterator implements Iterator {

    private List<Object> list;
    //记录遍历时的位置
    private int position = 0;

    public ObjectIterator(List<Object> list) {
        this.list = list;
    }

    @Override
    public boolean hasNext() {
        return position<list.size();
    }

    @Override
    public Object first() {
        return list.get(0);
    }

    @Override
    public Object next() {
        return list.get(position++);
    }
}
